package scau.mis4.chanyulin.tools.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by cyl on 2018/1/3.
 * 正则匹配通用工具类
 */
public class RegUtils {

    /**
     * 从一个字符串里面获取IP地址
     * @param target
     * @return
     */
    public static String getIP(String target) {
        String regex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(target);
        boolean result = matcher.find();
        if (result) return matcher.group();
        else return null;
    }

}
